import { Component, EventEmitter, Input, Output, OnInit, OnChanges } from '@angular/core';
import { SelectItem, DialogService } from 'primeng/primeng';
import { QkContentAttributes } from '../common/qk-content-attributes.component';

@Component({
    selector: 'qk-input-attributes',
    templateUrl: 'qk-input-attributes.component.html',
    styleUrls: ['qk-input-attributes.component.scss'],
    providers: []
})
export class QkInputAttributes implements OnInit {
    @Input() assembly;

    @Input() 
    set names(names: string[]){
        let temp = [];
        names.forEach(e => temp.push({label: e, value: e}));
        this.nameItems = temp;
    }
    //文字大小
    fontSize: SelectItem[] = [{ label: '12px', value: 12 }, { label: '14px', value: 14 }, { label: '16px', value: 16 }, { label: '18px', value: 18 }, { label: '24px', value: 24 }, { label: '36px', value: 36 }, { label: '48px', value: 48 }];
    //文字对齐方式
    textAlign: SelectItem[] = [{ label: '左对齐', value: "left" }, { label: '居中', value: "center" }, { label: "右对齐", value: "right" }];
    //字体
    fontFamily: SelectItem[] = [{ label: '微软雅黑', value: '"微软雅黑"' }, { label: '华文楷体', value: '"楷体","楷体_GB2312"' }, { label: '宋体', value: '"宋体"' }];
    //是否选项
    yesNo: SelectItem[] = [{ label: '否', value: false }, { label: '是', value: true }];;
    //检验方式
    patterns: SelectItem[] = [
        { label: '无', value: '' }, 
        { label: '数值', value: '\\\d+(\\\.\\\d+)?$'}, 
        { label: '整数', value: '\\\d+$'}, 
        { label: '邮箱', value: '^\\\w+([-+.]\\\w+)*@\\\w+([-.]\\\w+)*\\.\\\w+([-.]\\\w+)*$'}, 
        { label: '身份证号码', value: '(^\\\d{15}$)|(^\\\d{18}$)|(^\\\d{17}(\\\d|X|x)$)'},
        { label: '手机号码', value: '^1\\\d{10}$'}
    ];
    //系统接口
    interface: SelectItem[] = [
        { label: '自定义业务', value: 'custom' }
    ]
    nameItems: SelectItem[];
    constructor(public dialogService: DialogService) {
    }
    ngOnInit(){
    }
    
    /**编辑自动补全SQL */
    editContent(){
        debugger
        console.log(this.assembly);
        const ref = this.dialogService.open(QkContentAttributes, {
            header: '自动补全SQL',
            width: '450px',
            contentStyle: { 'height': '250px' },
            data: {
                content: this.assembly.configs.completeSQL || ''
            }
        });
        ref.onClose.subscribe(data => {
            this.assembly.configs.completeSQL = data;
        });
    }
}